import Http from "./http";
import store from "../store";
import {actions as WindowAction} from "../common/window/store";
import _ from 'lodash';
import EventBus from "@/util/EventBus";

export const SaveInputVCode = (value) => {
    if (_.isNull(value)) {
        value = '';
    }
    store.dispatch(WindowAction.saveVerificationCode(value));
    EventBus.emit('codeChange');
}


/**
 *
 * @param DOM dom元素id
 */
export default function (DOM) {
    Http.get('/sys/verification', {
        responseType: 'blob'
    }).then(res => {
        let blob = res;
        let reader = new FileReader();
        reader.readAsDataURL(blob);
        reader.onload = function (e) {
            try {
                document.getElementById(DOM).src = e.target.result.replace("data:text/xml;base64", "data:image/png;base64")
            } catch (e) {
                console.log(e)
            }
        }
    })
}
